﻿package view.mainUI
{
    import __AS3__.vec.*;
    import com.core.*;
    import com.greensock.*;
    import com.sh.game.global.*;
    import com.sh.game.util.*;
    import consts.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import uiresource.instances.ui.*;

    public class BossListCtrl extends NewFBUI
    {
        private var timer:int = 0;
        private var timeDic:Dictionary;
        private var posStrArr:Array;
        private var globalp:Point;
        private var subp:Point;
        private var _curmapid:int = 0;
        private var _datas:Array;
        private var _lastMapId:int = 0;
        private var isdown:Boolean = false;
        private var arr:Array;
        private var timeIDs:Vector.<int>;
        private var timevec:Array;
        private var taskObj:Object;

        public function BossListCtrl()
        {
            this.timeDic = new Dictionary();
            this.posStrArr = [];
            this.globalp = new Point();
            this.subp = new Point();
            this._datas = [];
            this.arr = new Array();
            this.timeIDs = new Vector.<int>;
            this.timevec = [];
            this.addEventListener(Event.ADDED, this.addstageHandler);
            btn_biaoqian.visible = false;
            btn_biaoqian1.visible = true;
            btn_biaoqian.addEventListener(MouseEvent.CLICK, this.clickHandler);
            btn_biaoqian1.addEventListener(MouseEvent.CLICK, this.clickHandler);
            this.addEventListener(MouseEvent.ROLL_OVER, this.doMouse);
            this.addEventListener(MouseEvent.ROLL_OUT, this.doMouse);
            txt_btn.addEventListener(MouseEvent.CLICK, this.clickHandler);
            img_bg.alpha = 0.3;
            return;
        }// end function

        protected function doMouse(event:MouseEvent) : void
        {
            switch(event.type)
            {
                case MouseEvent.ROLL_OVER:
                {
                    TweenLite.to(img_bg, 1, {alpha:1});
                    break;
                }
                case MouseEvent.ROLL_OUT:
                {
                    TweenLite.to(img_bg, 1, {alpha:0.3});
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        protected function addstageHandler(event:Event) : void
        {
            this.addEventListener(MouseEvent.MOUSE_DOWN, this.downHalder);
            GlobalLayer.instance.root.addEventListener(MouseEvent.MOUSE_UP, this.upHandler);
            GlobalLayer.instance.root.addEventListener(MouseEvent.MOUSE_MOVE, this.mouseHandler);
            toMap.addEventListener(MouseEvent.CLICK, this.openMap);
            return;
        }// end function

        public function openMap(event:Event) : void
        {
            ModelProxy.change("plugin", "change", {target:"map"});
            return;
        }// end function

        protected function outHandler(event:MouseEvent) : void
        {
            this.isdown = false;
            return;
        }// end function

        protected function mouseHandler(event:MouseEvent) : void
        {
            if (this.isdown)
            {
                this.globalp.x = this.parent.mouseX;
                this.globalp.y = this.parent.mouseY;
                this.x = this.parent.mouseX - this.subp.x;
                this.y = this.parent.mouseY - this.subp.y;
            }
            return;
        }// end function

        protected function downHalder(event:MouseEvent) : void
        {
            this.isdown = true;
            this.subp.x = this.mouseX;
            this.subp.y = this.mouseY;
            return;
        }// end function

        protected function upHandler(event:MouseEvent) : void
        {
            this.isdown = false;
            return;
        }// end function

        protected function clickHandler(event:MouseEvent) : void
        {
            box.visible = !box.visible;
            btn_biaoqian.visible = !box.visible;
            btn_biaoqian1.visible = box.visible;
            return;
        }// end function

        public function onShow(param1:Object) : void
        {
            var _loc_3:Object = null;
            var _loc_7:Object = null;
            var _loc_8:Object = null;
            var _loc_9:int = 0;
            var _loc_10:Object = null;
            var _loc_11:int = 0;
            var _loc_12:Object = null;
            var _loc_13:int = 0;
            var _loc_2:* = param1.bossList;
            var _loc_4:* = ConfigDictionary.data.weizhiandian;
            var _loc_5:* = UserData.getUserData("mapid");
            if (this._lastMapId != _loc_5)
            {
                this.arr = [];
                this._lastMapId = _loc_5;
            }
            var _loc_6:Array = [];
            for (_loc_7 in _loc_4)
            {
                
                _loc_10 = _loc_4[_loc_7];
                _loc_11 = _loc_10.mid;
                if (_loc_10.type == _loc_5)
                {
                    for each (_loc_12 in _loc_2)
                    {
                        
                        if (_loc_12.bossId == _loc_11)
                        {
                            this.arr[_loc_7] = {data:_loc_12, cfg:_loc_10};
                            break;
                        }
                    }
                }
            }
            for each (_loc_8 in this.arr)
            {
                
                _loc_6.push(_loc_8);
            }
            _loc_9 = _loc_6.length - 1;
            while (_loc_9 > 0)
            {
                
                _loc_13 = 0;
                while (_loc_13 < _loc_9)
                {
                    
                    if (_loc_6[_loc_13].data.state != 2)
                    {
                        if (_loc_6[(_loc_13 + 1)].data.state == 2)
                        {
                            _loc_3 = _loc_6[(_loc_13 + 1)];
                            _loc_6[(_loc_13 + 1)] = _loc_6[_loc_13];
                            _loc_6[_loc_13] = _loc_3;
                        }
                        else if (_loc_6[_loc_13].data.nextReliveTime > _loc_6[(_loc_13 + 1)].data.nextReliveTime)
                        {
                            _loc_3 = _loc_6[(_loc_13 + 1)];
                            _loc_6[(_loc_13 + 1)] = _loc_6[_loc_13];
                            _loc_6[_loc_13] = _loc_3;
                        }
                    }
                    _loc_13++;
                }
                _loc_9 = _loc_9 - 1;
            }
            this.taskObj = UserData.getData(UserDataType.Task);
            list.array = _loc_6;
            list.renderHandler = new Handler(this.mlistrender);
            this.visible = true;
            return;
        }// end function

        private function mlistrender(param1:Component, param2:int) : void
        {
            var _loc_3:Object = null;
            var _loc_4:Object = null;
            var _loc_5:Object = null;
            var _loc_6:Object = null;
            var _loc_7:Label = null;
            var _loc_8:Label = null;
            var _loc_9:int = 0;
            var _loc_10:int = 0;
            var _loc_11:int = 0;
            if (param2 < list.length)
            {
                _loc_3 = list.array[param2];
                _loc_4 = _loc_3.data;
                _loc_5 = _loc_3.cfg;
                _loc_6 = ConfigDictionary.data.monster;
                _loc_7 = param1.getChildByName("bossname") as Label;
                _loc_7.text = "<font color=\'#e7c39c\'><u><a href=\'event:1&" + UserData.getUserData("mapid") + "#" + _loc_5.mx + "#" + _loc_5.my + "\'>" + _loc_6[_loc_5.mid].name + "</a></u></font>";
                _loc_7.removeEventListener(TextEvent.LINK, this.linkHandler);
                _loc_7.addEventListener(TextEvent.LINK, this.linkHandler);
                _loc_8 = param1.getChildByName("time") as Label;
                delete this.timeDic[_loc_8];
                delete this.posStrArr[_loc_8];
                if (_loc_4.state == 2)
                {
                    _loc_8.text = "可击杀";
                    _loc_8.color = MColor.New62;
                    if (this.taskObj["tid_2004"] && this.taskObj["tid_2004"].state == 2 || this.taskObj["tid_2005"] && this.taskObj["tid_2005"].state == 2 || this.taskObj["tid_2006"] && this.taskObj["tid_2006"].state == 2 || this.taskObj["tid_2007"] && this.taskObj["tid_2007"].state == 2 || this.taskObj["tid_2008"] && this.taskObj["tid_2008"].state == 2)
                    {
                        ModelProxy.change("data", "wzadpos", UserData.getUserData("mapid") + "#" + _loc_5.mx + "#" + _loc_5.my);
                    }
                }
                else
                {
                    _loc_8.color = MColor.New52;
                    _loc_9 = _loc_4.nextReliveTime;
                    _loc_10 = Number(ModelProxy.getValue("data", "servertime") + getTimer()) / 1000;
                    _loc_11 = _loc_9 - _loc_10;
                    if (_loc_11 > 0)
                    {
                        _loc_8.text = "<font color =\'#e19f21\'>" + TimeDataFormatUtil.getLeftTime(_loc_11) + "后刷新</font>";
                        this.timeDic[_loc_8] = _loc_11;
                        this.posStrArr[_loc_8] = UserData.getUserData("mapid") + "#" + _loc_5.mx + "#" + _loc_5.my;
                        if (this.timer == 0)
                        {
                            this.timer = setInterval(this.doTime, 1000);
                        }
                    }
                    else
                    {
                        _loc_8.text = "可击杀";
                        _loc_8.color = MColor.New62;
                        if (this.taskObj["tid_2004"] && this.taskObj["tid_2004"].state == 2 || this.taskObj["tid_2005"] && this.taskObj["tid_2005"].state == 2 || this.taskObj["tid_2006"] && this.taskObj["tid_2006"].state == 2 || this.taskObj["tid_2007"] && this.taskObj["tid_2007"].state == 2 || this.taskObj["tid_2008"] && this.taskObj["tid_2008"].state == 2)
                        {
                            ModelProxy.change("data", "wzadpos", UserData.getUserData("mapid") + "#" + _loc_5.mx + "#" + _loc_5.my);
                        }
                    }
                }
            }
            return;
        }// end function

        private function doTime() : void
        {
            var _loc_1:Object = null;
            var _loc_2:String = null;
            for (_loc_1 in this.timeDic)
            {
                
                var _loc_5:* = this.timeDic;
                var _loc_6:* = _loc_1;
                var _loc_7:* = this.timeDic[_loc_1] - 1;
                _loc_5[_loc_6] = _loc_7;
                if (this.timeDic[_loc_1] > 0)
                {
                    _loc_1.text = "<font color =\'#e19f21\'>" + TimeDataFormatUtil.getLeftTime(this.timeDic[_loc_1]) + "后刷新</font>";
                    continue;
                }
                _loc_1.text = "可击杀";
                _loc_1.color = MColor.New62;
                this.taskObj = UserData.getData(UserDataType.Task);
                if (this.taskObj["tid_2004"] && this.taskObj["tid_2004"].state == 2 || this.taskObj["tid_2005"] && this.taskObj["tid_2005"].state == 2 || this.taskObj["tid_2006"] && this.taskObj["tid_2006"].state == 2 || this.taskObj["tid_2007"] && this.taskObj["tid_2007"].state == 2 || this.taskObj["tid_2008"] && this.taskObj["tid_2008"].state == 2)
                {
                    _loc_2 = ModelProxy.getValue("data", "wzadpos");
                    if (_loc_2 == null || _loc_2 == "")
                    {
                        ModelProxy.change("data", "wzadpos", this.posStrArr[_loc_1]);
                    }
                }
                delete this.timeDic[_loc_1];
                delete this.posStrArr[_loc_1];
            }
            return;
        }// end function

        protected function dostop(event:MouseEvent) : void
        {
            event.stopPropagation();
            return;
        }// end function

        protected function linkHandler(event:TextEvent) : void
        {
            var _loc_2:Array = null;
            var _loc_3:Array = null;
            var _loc_4:Array = null;
            _loc_2 = event.text.split("&");
            switch(int(_loc_2[0]))
            {
                case 1:
                {
                    _loc_3 = _loc_2[1].split("#");
                    ModelProxy.change("zone", "stopGuaji", null);
                    _loc_4 = [_loc_3[1], _loc_3[2], 0, _loc_3[0]];
                    ModelProxy.change("data", "taskfindmaster", _loc_4);
                    ModelProxy.change("data", "wzadpos", UserData.getUserData("mapid") + "#" + _loc_3[1] + "#" + _loc_3[2]);
                    ModelProxy.change("zone", "autoMove", {x:_loc_3[1], y:_loc_3[2], tostageid:_loc_3[0], onhorse:true});
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function close() : void
        {
            var _loc_1:int = 0;
            while (_loc_1 < this.timeIDs.length)
            {
                
                if (this.timeIDs[_loc_1] > 0)
                {
                    clearInterval(this.timeIDs[_loc_1]);
                    this.timeIDs[_loc_1] = 0;
                }
                _loc_1++;
            }
            this.visible = false;
            return;
        }// end function

    }
}
